package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"news/models"
)

type TypesController struct {
	beego.Controller
}

func (c *TypesController) List() {
	c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
	c.Ctx.Output.Header("Access-Control-Allow-Methods", "*")
	c.Ctx.Output.Header("Access-Control-Allow-Headers", "*")
	if c.Ctx.Input.Method() == "OPTIONS" {
		c.Ctx.Output.SetStatus(200)
		c.StopRun()
	}
	var types []models.Type
	models.DB.Find(&types)
	c.Data["json"] = models.Msg{
		Code: 200,
		Msg:  "",
		Data: types,
	}
	c.ServeJSON()
}
